
import Cookie from 'js-cookie'
export default{
    state:{
        isCollapse:false,
        valx:[
            {
                path: "/",
                name: "home",
                label: "首页",
                icon: "s-home",
                url: "Home/Home",
              }
        ],
        menu:[]
    },
    mutations:{
        // 修改菜单展开收起的方法
        collapseMenu(state){
     state.isCollapse=!state.isCollapse
        },
        hoot(state,val){
            console.log(val)
  if(val.name!=='home')
  {
  const index=state.valx.findIndex(item=>item.name===val.name)
  if(index===-1)
{
   state.valx.push(val)
}
        }
        console.log(state.valx)
    },
    setmenu(state,val)
    {
        state.menu=val
        Cookie.set('menu',JSON.stringify(val))
    },
    addmenu(state,router)
    {
        if(!Cookie.get('menu'))return
        const menu=JSON.parse(Cookie.get('menu'))
        state.menu=menu
        const menuArray=[]
        menu.forEach(item=>{
            if(item.children)
            {
               item.children=item.children.map(item=>{
                    item.component=()=>import(`../view/${item.url}`)
                    return item
                })
                menuArray.push(...item.children)
            }
            else{
                item.component=()=>import(`../view/${item.url}`)
                menuArray.push(item)
            }
              }) 
              menuArray.forEach(item=>{
              router.addRoute('Main',item)
        })
    },
    }
}